<?php 
    session_start();
    include_once '../sesslon.php';
    include_once '../inc/db.class.php';
    include_once '../inc/function.php';
    
    
    //读取会员基本信息
    $sql="select * from member where id=".getmid($_SESSION["jjusername"]);
    $rs=$db->getData($sql,true);
    
?>
<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<?php include_once '../meta.php'; ?>

		<link href="../assets/css/admin.css" rel="stylesheet" type="text/css">
		<link href="../assets/css/amazeui.css" rel="stylesheet" type="text/css">

		<link href="../css/personal.css" rel="stylesheet" type="text/css">
		<link href="../css/infstyle.css" rel="stylesheet" type="text/css">
		<script src="http://www.5imoban.net/download/jquery/jquery-2.1.4.js" type="text/javascript"></script>
		<script src="../assets/js/amazeui.js"></script>	
       <script src="../layer/layer.js"></script>
       <script src="../js/jquery.serializejson.js"></script>
		<script>
			function showwindow(){
				var w=$(window).width();
				var h=$(window).height();
				window.open("uppic.php","","height=300,width=600,left="+((w-600)/2)+",top="+((h-300)/2));
				
			}
			function saveinfo(){
				//判断填写数据格式是否正确
				var pre=/\'/;
				var pre2=/^[\u4e00-\u9fa5]{2,}$/;
				if(pre.test($("#username").val())){
					layer.alert("用户名包含特殊字符",{icon:5});
					return;
				}
				if($("#username").val().length<5 || $("#username").val().length>40){
					layer.alert("用户名长度不符合规则",{icon:5});
					return;
				}
				if(!pre2.test($("#realname").val())){
					layer.alert("格式不正确",{icon:5});
					return;
				}
				//console.info($("#f1").serializeJSON());
				$.ajax({
					url:"../ajax/saveinfo.php",
					data:$("#f1").serializeJSON(),
					type:"post",
					success:function(data){
						console.info(data);
						if(data==1){
							layer.alert("该用户名已经被别人注册",{icon:5});
						}else if(data==2){
							layer.msg("修改成功");
						}else if(data==3){
							layer.alert("修改失败",{icon:5});
						}else{
							layer.alert("修改失败",{icon:5});
						}
					},
					error:function(){
						console.info("ajax调用失败");	
					}
				});
			}
		</script>
	</head>

	<body>
		<?php include_once 'header1.php'; ?>
            <div class="nav-table">
					 <?php include_once 'header2.php'; ?>
			</div>
			<b class="line"></b>
		<div class="center">
			<div class="col-main">
				<div class="main-wrap">

					<div class="user-info">
						<!--标题 -->
						<div class="am-cf am-padding">
							<div class="am-fl am-cf"><strong class="am-text-danger am-text-lg">个人资料</strong> / <small>Personal&nbsp;information</small></div>
						</div>
						<hr/>

						<!--头像 -->
						<div class="user-infoPic">

							<div class="filePic">
								<img id="mypic" height="100" width="100" onclick="showwindow()" class="am-circle am-img-thumbnail" src="../memberimg/<?php if($rs["pic"]==""){echo "null.png";}else{echo $rs["pic"];} ?>"   alt="" />
							</div>   

							<p class="am-form-help">头像</p>

							<div class="info-m">
								<div><b>用户名：<i><?php echo $rs["username"];  ?></i></b></div>
								<div class="vip">
                                      <span></span><a href="#">会员专享</a>
								</div>
							</div>
						</div>

						<!--个人信息 -->
						<div class="info-main">
							<form id="f1" class="am-form am-form-horizontal">

								<div class="am-form-group">
									<label for="user-name2" class="am-form-label">用户名</label>
									<div class="am-form-content">
										<input name="username" value="<?php echo $rs["username"];  ?>" type="text" id="username" placeholder="nickname">
                                          <small>昵称长度不能超过40个汉字</small>
									</div>
								</div>

								<div class="am-form-group">
									<label for="user-name" class="am-form-label">姓名</label>
									<div class="am-form-content">
										<input name="realname" type="text" id="realname" value="<?php echo $rs["realname"];  ?>"  id="realname" placeholder="真实姓名">
                                         
									</div>
								</div>

								<div class="am-form-group">
									<label class="am-form-label">性别</label>
									<div class="am-form-content sex">
										<label class="am-radio-inline">
											<input type="radio" <?php if($rs["sex"]==0){echo "checked";} ?> name="sex" value="0" class="sex" data-am-ucheck> 男
										</label>
										<label class="am-radio-inline">
											<input type="radio" <?php if($rs["sex"]==1){echo "checked";} ?> name="sex" value="1" class="sex" data-am-ucheck> 女
										</label>
										<label class="am-radio-inline">
											<input type="radio" <?php if($rs["sex"]==2){echo "checked";} ?> name="sex" value="2" class="sex" data-am-ucheck> 保密
										</label>
									</div>
								</div>

								<div class="am-form-group">
									<label for="user-birth" class="am-form-label">生日</label>
									<div class="am-form-content birth">
										<input type="text" name="birthday" class="demo-input" id="birthday" value="<?php if($rs["birthday"]=="0000-00-00" || $rs["birthday"]==""){echo date("Y-1-1");}else{echo $rs["birthday"];} ?>" placeholder="请选择日期" id="birthday">
									</div>
							
								</div>
								
								<div class="am-form-group address">
									<label for="user-address" class="am-form-label">收货地址</label>
									<div class="am-form-content address">
										<a href="address.html">
											<p class="new-mu_l2cw">
												<span class="province">湖北</span>省
												<span class="city">武汉</span>市
												<span class="dist">洪山</span>区
												<span class="street">雄楚大道666号(中南财经政法大学)</span>
												<span class="am-icon-angle-right"></span>
											</p>
										</a>

									</div>
								</div>
								<div class="am-form-group safety">
									<label for="user-safety" class="am-form-label">账号安全</label>
									<div class="am-form-content safety">
										<a href="safety.html">

											<span class="am-icon-angle-right"></span>

										</a>

									</div>
								</div>
								<div class="info-btn">
									<div onclick="saveinfo()" class="am-btn am-btn-danger">保存修改</div>
								</div>

							</form>
						</div>

					</div>

				</div>
				<?php include_once '../footer.php'; ?>
			</div>

			<?php include_once 'aside.php'; ?>
		</div>
		<script src="../laydate/laydate.js"></script>
		<script>
		var ins22 = laydate.render({
            elem: '#birthday',
            min: '1900-1-1',
            max: '<?php echo date("Y-m-d"); ?>',
            ready: function(){
              ins22.hint('日期可选值设定在 <br> 2016-10-14 到 <?php echo date("Y-m-d"); ?>');
            }
          });
		</script>
	</body>

</html>